package com.sskj.mine.ui.activity;


import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.shizhefei.mvc.MVCCoolHelper;
import com.shizhefei.view.coolrefreshview.CoolRefreshView;
import com.sskj.common.adapter.slimadapter.IViewInjector;
import com.sskj.common.adapter.slimadapter.SlimAdapter;
import com.sskj.common.adapter.slimadapter.SlimInjector;
import com.sskj.common.base.App;
import com.sskj.common.box.decoration.DividerLineItemDecoration;
import com.sskj.lib.RConfig;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.mvchelper.ModelRx2DataSource;
import com.sskj.lib.util.NumberUtil;
import com.sskj.lib.util.TimeFormatUtil;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.bean.MineAccountRecord;
import com.sskj.mine.bean.MineCqtfBean;
import com.sskj.mine.presenter.MineAccountRecordActivityPresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

@Route(path = RConfig.MINE_ACCOUNT_RECORD)
public class MineAccountRecordActivity extends BaseActivity<MineAccountRecordActivityPresenter> {
    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.left_img)
    ImageView leftImg;
    @BindView(R2.id.left_tv)
    TextView leftTv;
    @BindView(R2.id.ivBack)
    LinearLayout ivBack;
    @BindView(R2.id.right_tv)
    TextView rightTv;
    @BindView(R2.id.ivRight)
    ImageView ivRight;
    @BindView(R2.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R2.id.coolRefreshView)
    CoolRefreshView coolRefreshView;
    private SlimAdapter slimAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mine_account_record;
    }

    @Override
    public MineAccountRecordActivityPresenter getPresenter() {
        return new MineAccountRecordActivityPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        tvTitle.setText(App.INSTANCE.getString(R.string.mine_mineAccountRecordActivity1_j));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerLineItemDecoration(this)
                .setFirstDraw(false)
                .setLastDraw(false)
                .setDividerColor(color(R.color.mine_BEC)));
        slimAdapter = SlimAdapter.create().register(R.layout.mine_account_record, new SlimInjector<MineCqtfBean>() {
            @Override
            public void onInject(MineCqtfBean commonBean, IViewInjector iViewInjector, List<Object> list) {
                iViewInjector.text(R.id.left, commonBean.getMemo())
                        .text(R.id.right, commonBean.getPrice())
                        .text(R.id.left2, TimeFormatUtil.SF_FORMAT_E.format(Double.valueOf(commonBean.getAddtime()) * 1000));
            }

        }).attachTo(recyclerView).updateData(new ArrayList());

        ModelRx2DataSource<MineCqtfBean> dataSource = new ModelRx2DataSource<>((ModelRx2DataSource.OnLoadSource<MineCqtfBean>)
                page -> mPresenter.getRecord(page + "", "20"), 20);
        MVCCoolHelper<List<MineCqtfBean>> mvcHelper = new MVCCoolHelper<>(coolRefreshView);
        mvcHelper.setDataSource(dataSource);
        mvcHelper.setAdapter(slimAdapter);
        mvcHelper.refresh();
    }
}
